import { ref,  onMounted } from 'vue'
import { defineStore } from 'pinia'
import { getListApi, addListApi, removeListApi } from '../api/list'

export const useProductStore = defineStore('product', () => {
  // 获取api数据
  const lists = ref([])
  // 获取列表数据
  onMounted(async () => {
    const res = await getListApi()
    lists.value = res
  })
  // 新增列表数据
  const addList = async (item) => {
    await addListApi(item)
    lists.value = await getListApi()
  }

  // 删除列表数据
  const deleteListItem = async (id) => {
    await removeListApi(id)
    lists.value = await getListApi()
  }



  return { lists, addList, deleteListItem }
})

